package com.itheima02.memory;

public class Demo2_Memory {
    public static void main(String[] args) {
        Ticket t = new Ticket();

        //开启线程
        new Thread(t, "窗口1").start();
        new Thread(t, "窗口2").start();
    }
}
class Ticket implements Runnable {
    int tickets = 100;

    @Override
    public void run() {
        while (true) {
            synchronized (Ticket.class) {
                if (tickets <=0 ) {
                    break;
                }
                System.out.println
                        (Thread.currentThread().getName() + "卖出了:" + tickets-- + "张票");
            }
        }
    }
}
